package com.digital.welcome.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.digital.welcome.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 韩
 */
@Mapper
@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from user where user_name = #{username}")
    User getUserByUsername(@Param("username") String username);

    @Select("select * from user where user_name in (select user_name from application where user_name = #{username})")
    User selectApplicationByUser(@Param("username") String username);

    @Update("update user set user_password =#{password} where user_name=#{username}")
    boolean updateUserPassword(@Param("username") String username, @Param("password") String password);

    @Select("select * from user where user_name in(select user_name from application)")
    List<User> getStudents();

    @Select("select * from user where user_name not in(select user_name from application) and category is not null")
    List<User> getNStudents();

    @Select("select * from user where user_name in(select user_name from application) and college = #{college}")
    List<User> getCollegeStudents(@Param("college") String college);

    @Select("select * from user where user_name not in(select user_name from application) and college = #{college}")
    List<User> getCollegeNStudents(@Param("college") String college);

    @Select("select * from user where user_name in(select user_name from pay where state = 1)")
    List<User> getPayStudents();

    @Select("select * from user where user_name not in(select user_name from pay where state = 1) and category is not null")
    List<User> getNPayStudents();

    @Select("select * from user where user_name in(select user_name from pay where state = 1) and college = #{college}")
    List<User> getCollegePayStudents(@Param("college") String college);

    @Select("select * from user where user_name not in(select user_name from pay where state = 1) and college = #{college}")
    List<User> getCollegeNPayStudents(@Param("college") String college);

    @Select("select * from `user` where user_name=#{userName} and classes like '%${classesName}%'")
    User getOneUserByClasses(String userName,String classesName);
}
